﻿<Window x:Uid="Window_1" x:Class="Up2dateConsole.Dialogs.RequestCertificate.RequestCertificateDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Up2dateConsole.Dialogs.RequestCertificate"
        xmlns:helpers="clr-namespace:Up2dateConsole.Helpers"
        mc:Ignorable="d"
        Title="Authorization" 
        WindowStartupLocation="CenterOwner"
        ResizeMode="NoResize" 
        SizeToContent="WidthAndHeight"
        IsEnabled="{Binding IsEnabled}"
        d:DataContext="{d:DesignInstance local:RequestCertificateDialogViewModel}">

    <Window.Resources>
        <ResourceDictionary x:Uid="ResourceDictionary_1">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Uid="ResourceDictionary_2" Source="..\..\Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <Style x:Uid="Style_1" TargetType="{x:Type Button}">
                <Setter x:Uid="Setter_1" Property="Padding" Value="5,4"/>
                <Setter x:Uid="Setter_2" Property="Margin" Value="5"/>
                <Setter x:Uid="Setter_3" Property="MinWidth" Value="70"/>
            </Style>

            <Style x:Uid="Style_2" TargetType="{x:Type TextBox}">
                <Setter x:Uid="Setter_4" Property="Padding" Value="2,4,2,2"/>
            </Style>

            <BooleanToVisibilityConverter x:Uid="BooleanToVisibilityConverter_1" x:Key="BooleanToVisibilityConverter"/>
            <helpers:NullToVisibilityConverter x:Uid="helpers:NullToVisibilityConverter_1" x:Key="NullToVisibilityConverter"/>
        </ResourceDictionary>
    </Window.Resources>

    <Grid x:Uid="Grid_1" Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition x:Uid="RowDefinition_1" Height="Auto"/>
            <RowDefinition x:Uid="RowDefinition_2" Height="Auto"/>
        </Grid.RowDefinitions>

        <StackPanel x:Uid="StackPanel_1" Margin="5">
            <StackPanel x:Uid="StackPanel_2" Orientation="Horizontal">
                <TextBlock x:Uid="TextBlock_1" Margin="0,0,10,0" VerticalAlignment="Top" 
                           Text="{StaticResource KeyIcon}" Foreground="DarkOrange" 
                           FontSize="42" FontFamily="{StaticResource FontAwesome}"/>
                <StackPanel x:Uid="StackPanel_3">
                    <TextBlock x:Uid="TextBlock_2" Margin="0,0,0,10" Text="Service connection has not been initialized yet"
                               Visibility="{Binding ShowExplanation, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <GroupBox x:Uid="GroupBox_1" Margin="0,0,0,10" Padding="0,4,0,0">
                        <Grid x:Uid="Grid_2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Uid="ColumnDefinition_3"/>
                                <ColumnDefinition x:Uid="ColumnDefinition_1" Width="Auto"/>
                                <ColumnDefinition x:Uid="ColumnDefinition_4"/>
                                <ColumnDefinition x:Uid="ColumnDefinition_2" Width="Auto"/>
                                <ColumnDefinition x:Uid="ColumnDefinition_5"/>
                            </Grid.ColumnDefinitions>
                            <RadioButton x:Uid="RadioButton_1" Grid.Column="1" Margin="0,5" HorizontalAlignment="Center" Content="Full protection (mTLS)" IsChecked="{Binding IsSecureConnection}"/>
                            <RadioButton x:Uid="RadioButton_2" Grid.Column="3" Margin="0,5" HorizontalAlignment="Center" Content="Development mode (plain token)" IsChecked="{Binding IsTestConnection}"/>
                        </Grid>
                    </GroupBox>
                    <StackPanel x:Uid="StackPanel_7" Visibility="{Binding IsSecureConnection, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock x:Uid="TextBlock_3" Text="Enter one-time key to automatically acquire authorization certificate"/>
                        <TextBox x:Uid="TextBox_1" Margin="0,10,0,5" Height="100" Width="500" FontSize="9" Text="{Binding OneTimeKey, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"/>
                        <StackPanel x:Uid="StackPanel_5" Orientation="Horizontal" Margin="0,0,0,10">
                            <TextBlock x:Uid="TextBlock_5" Text="or load the authorization certificate directly from file:" VerticalAlignment="Center"/>
                            <Button x:Uid="Button_3" Margin="10,0,0,0" Padding="5,4" MinWidth="0" VerticalAlignment="Center"
                            Command="{Binding LoadCommand}" ToolTip="Load certificate from file">
                                <TextBlock x:Uid="TextBlock_6" Text="{StaticResource FolderOpenIcon}" Style="{StaticResource ButtonIcon}"/>
                            </Button>
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_6" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10"
                            Visibility="{Binding MachineGuid, Converter={StaticResource NullToVisibilityConverter}}">
                            <TextBlock x:Uid="TextBlock_7" VerticalAlignment="Center" Text="Machine GUID:"/>
                            <TextBox x:Uid="TextBox_2" VerticalAlignment="Center" Margin="5,0"
                                Style="{StaticResource ReadOnlyInfoField}"
                                Text="{Binding MachineGuid, Mode=OneWay}"
                                ToolTip="RITMS UP2DATE service administartor may ask you for this Machine GUID when you request one-time key for client authorization."/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel x:Uid="StackPanel_8" Visibility="{Binding IsTestConnection, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock x:Uid="TextBlock_8" Text="DDI URL:"/>
                        <TextBox x:Uid="TextBox_3" Margin="0,5" Width="500" Text="{Binding HawkbitUrl, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock x:Uid="TextBlock_9" Text="Controller ID:"/>
                        <TextBox x:Uid="TextBox_4" Margin="0,5" Width="500" Text="{Binding ControllerId, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock x:Uid="TextBlock_10" Text="Security token (paste here generated token copied from dashboard):"/>
                        <TextBox x:Uid="TextBox_5" Margin="0,5" Width="500" Text="{Binding DeviceToken, UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </StackPanel>

        <StackPanel x:Uid="StackPanel_4" Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
            <TextBlock x:Uid="TextBlock_4" Style="{StaticResource RotatingStateIcon}" Text="{StaticResource SpinnerIcon}" Foreground="Green"
                       Visibility="{Binding IsInProgress, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <Button x:Uid="Button_1" Content="Authorize" Command="{Binding RequestCommand}"/>
            <Button x:Uid="Button_2" Content="Cancel" IsCancel="True"/>
        </StackPanel>
    </Grid>
</Window>
